<?php

namespace App\Console\Commands;

use App\Console\AdminMakerCommand;

class MakeAdminController extends AdminMakerCommand
{
    protected $type = 'admin控制器';

    protected $namespacePrefix = 'Http\Controllers\Admin';

    protected $stubPath = __DIR__ . '/stubs/controller.stub';

    protected $signature = 'admin:make-controller {name}';

    protected $description = '生成一个后台所需的控制器文件';

    protected function qualifyClass($name)
    {
        $controllerName = parent::qualifyClass($name);

        $controllerName = "{$this->namespacePrefix}\\{$controllerName}Controller";

        return $controllerName;
    }

    protected function buildClass($name)
    {
        return $this->replaceModel(parent::buildClass($name), $name);
    }

    protected function replaceModel($stub, $name)
    {
        $controllerName = str_replace($this->getNamespace($name) . '\\', '', $name);

        $modelName = str_replace_last('Controller', '', $controllerName);

        return str_replace('DummyModel', $modelName, $stub);
    }
}
